priority -50

extends c

# We want to overwrite everything in parent ft.
priority -49
###########################################################################
#			    Global functions 						  #
###########################################################################

global !p

def write_docstring_args(arglist, snip):
	args = str(arglist).split(',')

	if len(args) > 1:
		c = 0
		for arg in args:
			if c == 0:
				snip.rv += arg
				c = 1
			else:
				snip += '*       : %s' % arg.strip()
	else:
		snip.rv = args[0]


endglobal

###########################################################################
#                            TextMate Snippets                            #
###########################################################################
#

snippet /file "whb iqiyi file head" b
/**
* Copyright (C) 2021
* All rights reserved.
*
* Author     : Wang Haibin
* E-mail     : wanghaibin@qiyi.com
* Version    :
* Date       : `date`
* Destription:
*/
#pragma once

${1}

endsnippet

snippet /ccf "whb c++ class file.h generator" b
/**
* Copyright (C) 2021 All rights reserved.
*
* @file `!v vim_snippets#Filename('$1.h', 'name')`
* @author Wang Haibin
* @email wanghaibin@qiyi.com
* @date `date`
* @brief ${0}
*/
#pragma once

class ${1:`!p snip.rv = snip.basename or "name"`} {
public:
    /**
     * @brief 构造函数
     *
     * @param ${3}
     */
    ${1/(\w+).*/$1/} (${2:arguments});
    virtual ~${1/(\w+).*/$1/} ();

private:
};
endsnippet

snippet /ccf2 "whb c++ class file.h generator" b
/**
* Copyright (C) 2021 All rights reserved.
*
* @file `!v vim_snippets#Filename('$1.h', 'name')`
* @author Wang Haibin
* @email wanghaibin@qiyi.com
* @date `date`
* @brief ${0}
*/
#pragma once

class ${1:`!p snip.rv = snip.basename or "name"`} {
public:
    /**
     * @brief 构造函数
     *
     * @param ${3}
     */
    ${1/(\w+).*/$1/} (${2:arguments});
    ~${1/(\w+).*/$1/} ();

private:
    ${1/(\w+).*/$1/} (const ${1/(\w+).*/$1/}&);
    ${1/(\w+).*/$1/}& operator=(const ${1/(\w+).*/$1/}&);
};
endsnippet

snippet /fc1 "whb Basic c++ doxygen function template" b
/**
 * @brief ${4:brief}
 *
 * @param ${5:param}
 * @return ${6:return}
 */
${1:ReturnType} ${2:FunctionName}(${3:param});
endsnippet


snippet /fc2 "whb Basic c++ doxygen function template" b
/**
 * @brief ${4:brief}
 *
 * @param ${5:param}
 * @param ${6:param}
 * @return ${7:return}
 */
${1:ReturnType} ${2:FunctionName}(${3:param});
endsnippet

snippet /cf "whb Basic c++ doxygen function template" b
/**
 * @brief ${1:brief}
 *
 */
endsnippet

snippet /delete "whb delete" b
if (${1}) {
	delete ${1/(\w+).*/$1/} ;
	${1/(\w+).*/$1/} = NULL;
}
endsnippet

# 构造函数实现
snippet /cc "whb delete" b
${1:`!p snip.rv = snip.basename or "name"`}::${1/(\w+).*/$1/}() {}

${1/(\w+).*/$1/}::~${1/(\w+).*/$1/}() {}
endsnippet

snippet /cf0 "whb Basic c++ doxygen function template" b
/**
 * @brief ${1:brief}
 *
 * @return 
 */
endsnippet

snippet /cf1 "whb Basic c++ doxygen function template" b
/**
 * @brief ${1:brief}
 *
 * @param 
 * @return 
 */
endsnippet

snippet /cf2 "whb Basic c++ doxygen function template" b
/**
 * @brief ${1:brief}
 *
 * @param 
 * @param 
 * @return 
 */
endsnippet

snippet /cf3 "whb Basic c++ doxygen function template" b
/**
 * @brief ${1:brief}
 *
 * @param 
 * @param 
 * @param 
 * @return 
 */
endsnippet

snippet /cm "whb member"
${1:Value}; // ${2:Comments}
endsnippet

snippet main
int main() {
	${0}
}
endsnippet

snippet forc "general for loop (for)"
for (${6:auto} ${1:i} = ${2:v.begin()}; `!p import re; snip.rv = re.split("[^\w]",t[1])[-1]` ${4:!=} ${3:`!p m = re.search(r'^(?:(.*)(\.|->)begin\(\)|((?:std|boost)::)?begin\((.*)\))$', t[2]); snip.rv = (((m.group(3) if m.group(3) else "") + "end(" + m.group(4) + ")") if m.group(4) else (m.group(1) + m.group(2) + "end()")) if m else ""`}; ${5:++`!p snip.rv = t[1].split(" ")[-1]`}) {
	${VISUAL}$0
}
endsnippet

snippet beginend "$1.begin(), $1.end() (beginend)"
${1:v}${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}begin(), $1${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}end()
endsnippet

# snippet cl "class .. (class)"
# class ${1:`!p snip.rv = snip.basename or "name"`} {
# public:
# 	${1/(\w+).*/$1/} (${2:arguments});
# 	virtual ~${1/(\w+).*/$1/} ();
# 
# private:
# 	${0:/* data */}
# };
# endsnippet

snippet ns "namespace .. (namespace)"
namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`} {
	${VISUAL}$0
}${1/.+/ \/* /m}$1${1/.+/ *\/ /m}
endsnippet

snippet readfile "read file (readF)"
std::vector<char> v;
if (FILE *fp = fopen(${1:"filename"}, "r"))
{
	char buf[1024];
	while(size_t len = fread(buf, 1, sizeof(buf), fp))
		v.insert(v.end(), buf, buf + len);
	fclose(fp);
}
endsnippet

snippet map "std::map (map)"
std::map<${1:key}, ${2:value}> map$0;
endsnippet

snippet vector "std::vector (v)"
std::vector<${1:char}> v$0;
endsnippet

snippet tp "template <typename ..> (template)"
template <typename ${1:_InputIter}>
endsnippet

snippet cla "An entire .h generator" b
#ifndef ${2:`!v substitute(vim_snippets#Filename('$1_H','ClassName'),'.*','\U&\E','')`}
#define $2

class ${1:`!v substitute(substitute(vim_snippets#Filename('$1','ClassName'),'^.','\u&',''), '_\(\w\)', '\u\1', 'g')`}
{
private:
	$3

public:
	$1();
	virtual ~$1();
};

#endif /* $2 */
endsnippet


# snippet fnc "Basic c++ doxygen function template" b
# /**
# * @brief: ${4:brief}
# *
# * @param: `!p write_docstring_args(t[3],snip)`
# *
# * @return: `!p snip.rv = t[1]`
# */
# ${1:ReturnType} ${2:FunctionName}(${3:param})
# {
# 	${0:FunctionBody}
# }
# endsnippet

snippet boost_test "Boost test module" b
#define BOOST_TEST_MODULE ${1:TestModuleName}
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(${2:TestCaseName})
{
	${0:TestDefinition}
}

endsnippet

snippet boost_suite "Boost test suite module" b
#define BOOST_TEST_MODULE ${1:TestModuleName}
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(${2:SuiteName})

BOOST_AUTO_TEST_CASE(${3:TestCaseName})
{
	${0:TestDefinition}
}

BOOST_AUTO_TEST_SUITE_END()

endsnippet
snippet boost_test_fixture "Boost test module with fixture" b
#define BOOST_TEST_MODULE ${1:TestModuleName}
#include <boost/test/included/unit_test.hpp>

struct ${2:FixtureName} {
	$2() {}
	virtual ~$2() {}
	/* define members here */
};

BOOST_FIXTURE_TEST_CASE(${3:SuiteName}, $2)
{
	${0:TestDefinition}
}

endsnippet

snippet boost_suite_fixture "Boost test suite with fixture" b
#define BOOST_TEST_MODULE ${1:TestModuleName}
#include <boost/test/included/unit_test.hpp>

struct ${2:FixtureName} {
	$2() {}
	virtual ~$2() {}
	/* define members here */
};

BOOST_FIXTURE_TEST_SUITE(${3:SuiteName}, $2)

BOOST_AUTO_TEST_CASE(${4:TestCaseName})
{
	${0:TestDefinition}
}

BOOST_AUTO_TEST_SUITE_END()

endsnippet
# vim:ft=snippets:
